package com.my.note.mapper;

import com.my.note.pojo.UserData;
import com.my.note.pojo.UserRoleData;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

/**
 * @author lilun <a href="mailto:lil@chsi.com.cn">lilun</a>
 * @version $Id$ 2019年03月15 9:42
 */
@Component
@Mapper
public interface UserMapper {

    @Select("select * from note_user where username = #{username}")
    UserData getUserByUserName(@Param("username") String username);

    @Select("select * from note_user where id = #{id}")
    UserData getUserById(@Param("id") String id);

    @Select("select * from note_user order by username")
    List<UserData> getUserList();

    @Select("select * from note_user_role where userId= #{userId}")
    List<UserRoleData> getUserRoleByUserId(@Param("userId") String userId);

    @Insert("insert into note_user(id,username,password) values(#{id},#{username},#{password})")
    void saveUser(@Param("id") String id, @Param("username") String username, @Param("password") String password);

    @Delete("delete from note_user where id=#{id}")
    void deleteUser(@Param("id") String id);

    @Insert("insert into note_user_role(id,roleId,userId) values(#{id},#{roleId},#{userId})")
    void saveUserRole(@Param("id") String id, @Param("roleId") String roleId, @Param("userId") String userId);

    @Delete("delete from note_user_role where id=#{id}")
    void deleteUserRole(@Param("id") String id);



}
